package com.qf.fmall.user.controller;

import com.qf.fmall.user.service.IUserService;
import com.qf.fmall.vo.ResultVo;
import com.qf.fmall.vo.UserRegistVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author dongjunlong
 * @since 2024-01-15
 */
@CrossOrigin // 跨域
@RestController
@RequestMapping("/user")
@Slf4j // 打印日志的注解
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/regist")
    public ResultVo regist(@RequestBody UserRegistVo userRegistVo) {
        // 打印接口传入的参数
        log.info("接收到的注册用户信息为：userRegistVo={}", userRegistVo);

        // 将注册逻辑交给 service去处理
        boolean flag = userService.regist(userRegistVo);

        if (flag) {
            return new ResultVo(10000, "ok", null);
        } else {
            return new ResultVo(-10000, "error", null);
        }

    }

    @RequestMapping("/login")
    public ResultVo login(String username, String password) {

        // 打印接口传入的参数
        log.info("接收到的登录用户信息为：username={},password={}", username, password);


        ResultVo resultVo = userService.login(username, password);

        return resultVo;

    }
}
